import Vue from 'vue'

Vue.directive('Throttle', {
  inserted: function (el, binding) {
    let last;
    let timer;
    let { fn, interval = t || 500 } = binding.value;
    return function () {
      let args = arguments;
      let now = +new Date();
      if (last && now - last < interval) {
        clearTimeout(timer);
        timer = setTimeout(() => {
          last = now;
          fn.apply(this, args);
        }, interval);
      } else {
        last = now;
        fn.apply(this, args);
      }
    };
  }
})